﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using SpringStudio.Common;
using SpringStudio.DAL;

namespace Sdepci.InfoCode.BLL.CodeDesign
{
    /// <summary>
    /// 详细信息编码表
    /// </summary>
    public class Info
    {
        #region 属性定义

        private string _infoGuid;
        /// <summary>
        /// 编码编号
        /// </summary>
        public string InfoGuid
        {
            get { return this._infoGuid; }
        }

        private string _infoCode;
        /// <summary>
        /// 信息编码
        /// </summary>
        public string InfoCode
        {
            get { return this._infoCode; }
        }

        private string _infoDesc;
        /// <summary>
        /// 编码说明
        /// </summary>
        public string InfoDesc
        {
            get { return this._infoDesc; }
        }

        private string _ruleGuid;
        /// <summary>
        /// 编码类型编号
        /// </summary>
        public string RuleGuid
        {
            get { return this._ruleGuid; }
        }

        private string _createTime;
        /// <summary>
        /// 创建时间
        /// </summary>
        public string CreateTime
        {
            get { return this._createTime; }
        }

        private string _createUserId;
        /// <summary>
        /// 创建者证档号
        /// </summary>
        public string CreateUserId
        {
            get { return this._createUserId; }
        }

        private string _serialReference;
        /// <summary>
        /// 流水号参考码
        /// </summary>
        public string SerialReference
        {
            get { return this._serialReference; }
        }

        private string _serialNumber;
        /// <summary>
        /// 当前流水号值
        /// </summary>
        public string SerialNumber
        {
            get { return this._serialNumber; }
        }

        #endregion

        #region 构造方法

        public Info(string infoGuid)
        {
            this._infoGuid = infoGuid;

            try
            {
                string sql = "Select InfoGuid,InfoCode,InfoDesc,RuleGuid,CreateTime,CreateUserId,SerialReference,SerialNumber From InfoCodeInfo Where InfoGuid=@InfoGuid";
                DataSet ds = SqlHelper.ExecuteDataSet(ConnectionString.Default, CommandType.Text, sql,
                    SqlHelper.NewSqlParameter("@InfoGuid", this._infoGuid));
                if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    DataRow row = ds.Tables[0].Rows[0];
                    this._infoGuid = row["InfoGuid"].ToString();
                    this._infoCode = row["InfoCode"].ToString();
                    this._infoDesc = row["InfoDesc"].ToString();
                    this._ruleGuid = row["RuleGuid"].ToString();
                    this._createTime = row["CreateTime"].ToString();
                    this._createUserId = row["CreateUserId"].ToString();
                    this._serialReference = row["SerialReference"].ToString();
                    this._serialNumber = row["SerialNumber"].ToString();
                }
                else
                {
                    throw new Exception("没有找到该值对应的详细记录！（参数：infoGuid'" + this._infoGuid + "'）");
                }
            }
            catch (Exception ex)
            {
                ExceptionHandler.Handle(ex);
            }
        }

        #endregion

    }
}
